package com.csdj.DriverSchoolSystem.util;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

public class MessageLangUtil {

    private static Map<String,ResourceBundle> langMap = new HashMap<>();


    /**
     * 读取语言包
     * @param name
     * @param lang
     * @return
     */
    public static ResourceBundle readBundle(String name,String lang){
        return ResourceBundle.getBundle(name, Locale.forLanguageTag(lang));
    }

    public static String getMsg(int code,String lang){
        ResourceBundle resourceBundle = langMap.get(lang);
        if(resourceBundle == null){
            resourceBundle = readBundle("message",lang);
            langMap.put(lang,resourceBundle);
        }
        return resourceBundle.getString(String.valueOf(code));
    }
}
